package com.sjz.han.industry.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sjz.han.industry.R;
import com.sjz.han.industry.activites.MemberDetailActivity;
import com.sjz.han.industry.activites.TeamTwoActivity;
import com.sjz.han.industry.entities.MainTeamEntity;

import java.util.ArrayList;
import java.util.List;


/**
 *团队适配器
 */
public class MainTeamDown1Adapter extends RecyclerView.Adapter<MainTeamDown1Adapter.ViewHolder> {
    private Context context;
    private List<MainTeamEntity.MainTeamData.MainUser.C2User.C1User.BUser.AUser> datas = new ArrayList<>();
    public MainTeamDown1Adapter(Context context) {
        this.context=context;
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
//        return 3;
    }
    public void setAdapterDatas(List<MainTeamEntity.MainTeamData.MainUser.C2User.C1User.BUser.AUser> datas){
        this.datas=datas;
        notifyDataSetChanged();
    }
    @Override
    public MainTeamDown1Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MainTeamDown1Adapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_teamtwo_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final MainTeamDown1Adapter.ViewHolder holder, final int position) {
         holder.teamA_photo_img.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 context.startActivity(new Intent(context, MemberDetailActivity.class).putExtra("userId",datas.get(position).userId));
             }
         });
        holder.team_name_tv.setText("姓名："+datas.get(position).username);
        holder.team_phone_tv.setText("联系电话："+datas.get(position).phone);
        holder.team_temanum_tv.setText("下属团队："+datas.get(position).nextCount+"人");

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public ImageView teamA_photo_img;
        public TextView team_name_tv,team_phone_tv,team_temanum_tv;
        public ViewHolder(View itemView) {
            super(itemView);
            teamA_photo_img=(ImageView)itemView.findViewById(R.id.teamA_photo_img);
            team_name_tv=(TextView)itemView.findViewById(R.id.teamA_name_tv);
            team_phone_tv=(TextView)itemView.findViewById(R.id.teamA_phone_tv);
            team_temanum_tv=(TextView)itemView.findViewById(R.id.teamA_teamnum_tv);

        }

    }
}